pg_query is error -> select datas.ken_cd, datas.ken_name , datas.shiku_cd , datas.shiku_name, datas.shiku_cd as cd, datas.shiku_name as nm, datas.object_count as cnt from (select town.ken_cd, town.ken_name, town.shiku_cd, town.shiku_name, town.p_sort, coalesce(obj1.object_count, 0, obj1.object_count) as object_count from v_town town inner join m_shop_town shek on shek.shiku_cd = town.shiku_cd and substr(shop_cd , 1 , 3) = '112' left outer join ( select shiku_cd, count(*) as object_count from d_object_data where substr(shop_cd , 1 , 3) = '112' and shubetu_cd in (%27%20 %20shubetucd%20 %20%27) and org_regist_cd is null and koukai_flag in (1,2,4) and ( ( rosen_cd1 in ('%27%20 %20$(this).find(%27data1%27).text()%20 %20%27') ) or( rosen_cd2 in ('%27%20 %20$(this).find(%27data1%27).text()%20 %20%27') ) or( rosen_cd3 in ('%27%20 %20$(this).find(%27data1%27).text()%20 %20%27') )) group by shiku_cd ) obj1 on town.shiku_cd = obj1.shiku_cd group by town.ken_cd, town.ken_name, town.shiku_cd, town.shiku_name, town.p_sort, obj1.object_count ) datas, (select shiku_cd, min(sort) as k_sort from m_shop_town where substr(shop_cd , 1 , 3) = '112' group by shiku_cd ) shiku_cds where datas.shiku_cd = shiku_cds.shiku_cd order by datas.p_sort,shiku_cds.k_sort,datas.shiku_cd